<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Management/Manage.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="CSI.Directory.Core.Model"%>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Add an Admin
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    $(document).ready(function() {

        $("a").removeClass("current");
        $("#categories").addClass("current");
        var e = jQuery.Event("click");
        $("#categories").trigger(e);
        $("#add-category").addClass("current");

    });
</script>
    
    
<div class="content-box">
        <!-- Start Content Box -->
        <div class="content-box-header">
            <h3>
                Add Category</h3>
            
            <div class="clear">
            </div>
        </div>
        <!-- End .content-box-header -->
        <div class="content-box-content">
            <div class="tab-content default-tab" id="tab1">
        
    
   <form action="/Management/AddCategory" name="form1" method="post">            
       <fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
							
		<p>
			<label>Name</label>
				<input class="text-input small-input" type="text" id="name" name="name" /> 
				
				
		</p>
		<p>
			<label>Alias</label>
				<input class="text-input small-input" type="text" id="alias" name="alias" /> 
				
				
		</p>
		<p>
			<label>Parent Category</label>
				<select name="parent" >
                   <option value="0">None</option>
                    <%foreach (var c in ((IList<Category>)ViewData["Categories"]).Where(t => t.ParentId == 0))
                     {%>
                         <option value="<%=c.Id %>"><%=c.Name%></option>
                     <% }%> 
                        
                    </select>
				
		</p>
		
         <input type="button" onclick="return DoAjaxSubmit(this);" value="Add" class="button" />
         <div id="results"></div>
        </fieldset>
   </form>
    </div>
        </div>
    </div>
    
    <script type="text/javascript">
        function DoAjaxSubmit(btnClicked) {
            var filter = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
            var form = $(btnClicked).parents('form');

            if ($("#name").val() == "" && $("#alias").val() == "") {
                $("#results").html("Please complete all fields.").addClass("red");

                return false;
            }
            else {
                $("#results").html("");
                $.ajax({
                    type: "POST",
                    url: form.attr('action'), //'<%=ResolveUrl("~/register/go") %>',
                    data: form.serialize(),
                    error: function(xhr, status, error) {
                    },
                    success: function(response) {
                        if (response != null) {
                            if (!response.Successful) {
                                $("#results").html("An error occurred: " + response.Exception).addClass("red");
                                return false;
                            }
                            else {
                                $("#results").html("Category added").addClass("green");
                                document.form1.reset();
                            }
                        }
                    }
                });
            }
            return false;
        }
    </script>

</asp:Content>
